﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Diagnostics;
namespace Skyper.Shared {
	[DataContract(Name="Chat")]
	public sealed class ChatModel : BaseModel {
		#region Fields
		private static readonly Type MyType = typeof(ContactModel);
		#endregion
		#region Protected
		protected sealed override DataContractSerializer CreateSerializer() {
			return new DataContractSerializer(MyType);
		}
		#endregion
		#region Public
		public sealed override bool Suspend(Stream stream) {
			//Check if stream is ok.
			if (stream == null || !stream.CanWrite) {
				return false;
			}

			var ds = this.Serializer;

			try {
				ds.WriteObject(stream, this);

				return true;
			} catch (Exception exc) {
				Debug.WriteLine(exc);

				return false;
			}
		}
		public sealed override bool Resume(Stream stream) {
			//Check if stream is ok.
			if (stream == null || !stream.CanRead) {
				return false;
			}

			var ds = this.Serializer;
			try {
				var me = ds.ReadObject(stream) as ChatModel;
				if (me == null) {
					return false;
				}

				this.Created = me.Created;
				this.Partner = me.Partner;
				this.Updated = me.Updated;

				return true;
			} catch (Exception exc) {
				Debug.WriteLine(exc);

				return false;
			}
		}
		#endregion
		#region Property
		/// <summary>
		/// Gets or sets the partner username.
		/// </summary>
		/// <value>
		/// The partners username.
		/// </value>
		[DataMember(IsRequired=false,EmitDefaultValue=false)]
		public String Partner {
			get;
			set;
		}
		[DataMember(IsRequired = false, EmitDefaultValue = false)]
		public DateTime Created {
			get;
			set;
		}
		[DataMember(IsRequired = false, EmitDefaultValue = false)]
		public DateTime Updated {
			get;
			set;
		}
		#endregion
	}
}
